package com.chankudo.demo3;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

public class Demo3BeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("---postProcessBeforeInitialization--->");
        //这个方法的使用场景是什么？
        //例如：我们队实现了某一个接口的类
        //统一在这些类的bean的初始化完成并设置了property之后
        //进一步的做一些操作（比如：某些property的设置和修改）
        if(bean instanceof LifeCycleDemo){
            System.out.println("---beanName:"+beanName+"--->");
            return bean;
        }
        return null;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("---postProcessAfterInitialization--->");
        if(bean instanceof LifeCycleDemo){
            System.out.println("---beanName:"+beanName+"--->");
            return bean;
        }
        return null;
    }
    
}
